home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / lstIndex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-19  |  1.5 KB  |  65 lines

  1. /*-
  2.  * lstIndex.c --
  3.  *    Function to return the index of a datum in a Lst.
  4.  *
  5.  * Copyright (c) 1988 by the Regents of the University of California
  6.  *
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appears in all copies.  The University of California nor
  11.  * Adam de Boor makes any representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  *
  16.  */
  17. #ifndef lint
  18. static char *rcsid =
  19. "$Id: lstIndex.c,v 1.2 88/11/17 20:52:54 adam Exp $ SPRITE (Berkeley)";
  20. #endif lint
  21.  
  22. #include    "lstInt.h"
  23.  
  24. /*-
  25.  *-----------------------------------------------------------------------
  26.  * Lst_Index --
  27.  *    Return the index of a datum in a Lst. Indices start at 0.
  28.  *
  29.  * Results:
  30.  *    Returns -1 if the datum isn't in the Lst, or the index of
  31.  *    the datum if it is.
  32.  *
  33.  * Side Effects:
  34.  *    None.
  35.  *
  36.  *-----------------------------------------------------------------------
  37.  */
  38. int
  39. Lst_Index(l, d)
  40.     Lst                  l;
  41.     ClientData          d;
  42. {
  43.     List              list = (List)l;
  44.     register ListNode    lNode;
  45.     register int      index;
  46.  
  47.     lNode = list->firstPtr;
  48.  
  49.     if (lNode == NilListNode) {
  50.     return(-1);
  51.     }
  52.  
  53.     index = 0;
  54.  
  55.     do {
  56.     if (lNode->datum == d) {
  57.         return(index);
  58.     } else {
  59.         lNode = lNode->nextPtr;
  60.         index += 1;
  61.     }
  62.     } while (lNode != NilListNode && lNode != list->firstPtr);
  63.     return(-1);
  64. }
  65.